package cn.exempale.mscapplication.model.net.callback;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import cn.exempale.mscapplication.emnus.StatusType;

/**
 * 网络访问状态与结果
 */
public class Resource<T> {

    @NonNull
    public final StatusType status;
    @Nullable
    public final T data;
    @Nullable
    public final String msg;

    private Resource(@NonNull StatusType status, @Nullable T data, @Nullable String msg) {
        this.status = status;
        this.data = data;
        this.msg = msg;
    }

    public static <T> Resource<T> success(@Nullable T data) {
        return new Resource<>(StatusType.SUCCESS, data, null);
    }

    public static <T> Resource<T> error(@Nullable String msg) {
        return new Resource<>(StatusType.ERROR, null, msg);
    }

    public static <T> Resource<T> incorrect() {
        return new Resource<>(StatusType.INCORRECT, null, null);
    }

    public static <T> Resource<T> loading(@Nullable String msg) {
        return new Resource<>(StatusType.LOADING, null, msg);
    }
}
